<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图表</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
    <style>
        .grid-container {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            grid-column-gap: 10px;
            background-color: whitesmoke;

        }
        .grid-item {
            background-color: white;
        }
    </style>
</head>
<body>
<div class="grid-container">
    <div class="grid-item"  id="main" style="width: 100%;height:400px;"></div>
    <div class="grid-item" id="main2" style="width: 100%;height:400px;"></div>
    <div class="grid-item" id="main3" style="width: 100%;height:400px;"></div>
</div>

<script>
    $(function () {
        $.ajax({
            url:"yg.php",
            success(res){
                chart1(res.data.x , res.data.y)

               //console.log(res.data)
            },
            error() {
                alert('请求失败')
            }
        })
    })
    $(function () {
        $.ajax({
            url:"sex.php",
            success(res){
                chart2(res.data.data)
                chart3()
                //console.log(res.data.data)
            },
            error() {
                alert('请求失败')
            }
        })
    })
    $(function () {
        $.ajax({
            url:"money.php",
            success(res){
                chart3(res.data.x, res.data.y)
                //console.log(res.data)
            },
            error() {
                alert('请求失败')
            }
        })
    })
</script>
<script type="text/javascript">
    //柱状图
   function chart1(xData ,yData) {
       // 基于准备好的dom，初始化echarts实例
       var myChart = echarts.init(document.getElementById('main'));

       // 指定图表的配置项和数据
       var option = {
           title: {
               text: '部门统计',

           },
           toolbox: {
               show:'true',
               feature: {
                   saveAsImage:{
                       type : 'png'
                   }
               }
           },
           tooltip: {},
           legend: {
               data: ['人数']
           },
           xAxis: {
               data: xData
           },
           yAxis: {},
           series: [
               {
                   name: '人数',
                   type: 'bar',
                   data: yData
               }
           ]
       };

       // 使用刚指定的配置项和数据显示图表。
       myChart.setOption(option);
   }
   //饼图
   function chart2(data) {
       // 基于准备好的dom，初始化echarts实例
       var myChart = echarts.init(document.getElementById('main2'));
       // 指定图表的配置项和数据
        var option = {
           title: {
               text: '男女生比例',
               left: 'center'
           },
            toolbox: {
                show:'true',
                feature: {
                    saveAsImage:{
                        type : 'png'
                    }
                }
            },
           tooltip: {
               trigger: 'item'
           },
           legend: {
               orient: 'vertical',
               left: 'left'
           },
           series: [
               {
                   name: '男女生比例',
                   type: 'pie',
                   radius: '50%',
                   data: data,
                   emphasis: {
                       itemStyle: {
                           shadowBlur: 10,
                           shadowOffsetX: 0,
                           shadowColor: 'rgba(0, 0, 0, 0.5)'
                       }
                   }
               }
           ]
       };

       // 使用刚指定的配置项和数据显示图表。
       option && myChart.setOption(option);
   }
   //折线图
    function chart3(x, y) {

        var myChart = echarts.init(document.getElementById('main3'));
        option = {
            title: {
                text: '李四工资',
                left: 'center'
            },
            xAxis: {
                type: 'category',
                data: x
            },
            toolbox: {
                show:'true',
                feature: {
                    saveAsImage:{
                        type : 'png'
                    }
                }
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data: y,
                    type: 'line',
                    smooth: true
                }
            ]
        };

        option && myChart.setOption(option);

    }
</script>
</body>
</html>